package com.cls.business.service.impl;

import com.cls.common.entity.QueryRequest;
import com.cls.business.entity.ApplicantInfo;
import com.cls.business.mapper.ApplicantInfoMapper;
import com.cls.business.service.IApplicantInfoService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
import lombok.RequiredArgsConstructor;
import com.github.pagehelper.PageHelper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 申请人信息表 Service实现
 *
 * @author wandering
 * @date 2020-11-11 18:15:13
 */
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class ApplicantInfoServiceImpl extends ServiceImpl<ApplicantInfoMapper, ApplicantInfo> implements IApplicantInfoService {

    @Override
    public PageInfo<ApplicantInfo> findApplicantInfos(QueryRequest request, ApplicantInfo applicantInfo) {
        LambdaQueryWrapper<ApplicantInfo> queryWrapper = new LambdaQueryWrapper<>();
        // TODO 设置查询条件
        PageHelper.startPage(request.getPageNum(), request.getPageSize());
        List<ApplicantInfo> list = this.list(queryWrapper);
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }

    @Override
    public List<ApplicantInfo> findApplicantInfos(ApplicantInfo applicantInfo) {
        LambdaQueryWrapper<ApplicantInfo> queryWrapper = new LambdaQueryWrapper<>();
        // TODO 设置查询条件
        return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    public ApplicantInfo findByIdentity(String identity) {

        return this.baseMapper.findByIdentity(identity);
    }

    @Override
    public ApplicantInfo findByUserId(Long userId) {
        return this.baseMapper.findByUserId(userId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createApplicantInfo(ApplicantInfo applicantInfo) {
        this.save(applicantInfo);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateApplicantInfo(ApplicantInfo applicantInfo) {
        this.saveOrUpdate(applicantInfo);
    }


    /**
     * 删除
     *
     * @param ids
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteApplicantInfos(String[] ids) {
        List<String> list = Arrays.asList(ids);
        this.removeByIds(list);
    }

}
